package org.example.translate_braille.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.example.translate_braille.entity.Photo;
import org.example.translate_braille.entity.Record;
import org.example.translate_braille.entity.User;
import org.example.translate_braille.mapper.RecordMapper;
import org.example.translate_braille.resdata.DataEnum;
import org.example.translate_braille.resdata.X;
import org.example.translate_braille.service.PhotoService;
import org.example.translate_braille.service.RecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.translate_braille.utils.TencentCosUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Jacky
 * @since
 */
@Service
@Slf4j
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    @Autowired
    RecordService recordService;

    @Override
    public X<Record> showRecordList(String userId) {
        try {
            //构造器
            QueryWrapper<Record> queryable = new QueryWrapper<>();
            queryable.lambda()
                    .eq(Record::getUserId, userId)
                    .eq(Record::getIsDeleted,0)
                    .orderByDesc(Record::getCreateTime)
            ;
            return X.ResData(DataEnum.SUCCESS, recordService.list(queryable));
        }catch(Exception e){
            return X.ResData(DataEnum.SELECT_FAIL, Convert.toStr(e));
        }
    }

    @Override
    public X<Record> inOrUpRecord(Record record) {
        try {
            recordService.saveOrUpdate(record);
            return X.ResData(DataEnum.SUCCESS,record);
        }catch(Exception e){
            return X.ResData(DataEnum.INSERT_FAIL, Convert.toStr(e));
        }

    }

    @Override
    public X<Record> deleteRecord(Record record) {
        return null;
    }
}
